package com.qf.java2201.web;

import com.alibaba.fastjson.JSON;
import com.qf.java2201.common.R;
import com.qf.java2201.service.OrderService;
import com.qf.java2201.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @date 2022/4/9
 * @desc  检查  某日期 某时间段  某医生的 预约单是否已满
 */
@WebServlet("/checkDate")
public class CheckDateServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //预约日期
        String odate = req.getParameter("odate");
        // 预约时间段
        String sjdid = req.getParameter("sjdid");

        //预约的医生 id
        String edid = req.getParameter("edid");

        OrderService orderService = new OrderServiceImpl();

        //检查这个医生 在这个日期  这个时间段能不能被预约
        boolean b = orderService.checkDate(odate,edid,sjdid);


        PrintWriter writer = resp.getWriter();

        if(b){
            R ok = R.ok();
            String s = JSON.toJSONString(ok);
            writer.println(s);
        }else{
            R error = R.error();
            String s = JSON.toJSONString(error);
            writer.println(s);
        }
    }
}
